// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 1e5+50;

int u[N], v[N];

int n;

vector<int> G[N];

int ans[N];


int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &n);
    for (int i=0; i<n-1; ++i) {
        scanf("%d%d", &u[i], &v[i]);
        G[u[i]].push_back(i);
        G[v[i]].push_back(i);
    }

    memset(ans, -1, sizeof ans);
    int now = 0;
    for (int i=1; i<=n; ++i) {
        if (G[i].size() == 1 && ans[G[i][0]] == -1)
            ans[G[i][0]] = now++;
    }

    for (int i=0; i<n-1; ++i) {
        if (ans[i] == -1)
            ans[i] = now++;
    }

    for (int i=0; i<n-1; ++i)
        printf("%d\n", ans[i]);

    return 0;
}
